package com.jeesite.test;

import com.jeesite.common.io.IOUtils;
import com.jeesite.common.utils.ClassUtils;
import org.junit.Test;

import java.io.IOException;
import java.io.InputStream;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class ColumnExtractor {


    private static Map<String, String> typeMapping = new HashMap<>();

    static {
        typeMapping.put("bigint","Long");
        typeMapping.put("datetime","Date");
        typeMapping.put("varchar","String");
        typeMapping.put("int","Integer");
        typeMapping.put("integer","Integer");
        typeMapping.put("date","Date");
        typeMapping.put("decimal","Double");
        typeMapping.put("double","double");
        typeMapping.put("text","String");
        typeMapping.put("tinyint","Integer");
    }

    private String toField(String columnData){
        String[] arr = columnData.split("\\s+");
        String fieldName = ClassUtils.camelCharset(arr[0]);
        String type = arr[1];
        return "private "+typeMapping.get(type)+" "+fieldName+";";
    }

    @Test
    public void testColumnCamel(){
        try {
            InputStream inputStream = this.getClass().getClassLoader().getResourceAsStream("columns.txt");
            List<String> lines = IOUtils.readLines(inputStream, "UTF-8");
            lines.forEach(item->{
                System.out.println(toField(item));
            });
        } catch (IOException e) {
            throw new RuntimeException(e);
        }

    }
}
